package sk.ygor.raynor.client.test;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import sk.ygor.raynor.client.json.JSONSerializer;
import sk.ygor.raynor.client.json.JSONSerializerFactory;
import sk.ygor.raynor.client.service.JSONService;

import java.util.List;
import java.util.Map;

public class RaynorTestInterfaces {
    public static final Serializers serializers() {
        final Serializers serializers = GWT.create(Serializers.class);
        final JSONSerializerFactory.Configuration cfg = (JSONSerializerFactory.Configuration) serializers;
        cfg.setTransformer(new JSONSerializer.DefaultTransformer()); // redundant call - only for demonstration
        return serializers;
    }

    public static interface IntegerSerializer extends JSONSerializer<Integer> {

    }

    public static interface ParentSerializer extends JSONSerializer<RaynorTestClasses.Parent> {

    }

    public static interface CollectionTypeSerializers extends JSONSerializerFactory {
        public JSONSerializer<List<RaynorTestClasses.Person>> listOfPerson();
        public JSONSerializer<RaynorTestClasses.Person[]> arrayOfPerson();
        public JSONSerializer<Map<String, RaynorTestClasses.Person>> stringMapOfPerson();
    }

    public static interface SerializersForPrimitives extends JSONSerializerFactory {

        public JSONSerializer<Character> sCharacter();

        public JSONSerializer<String> sString();

        public JSONSerializer<Byte> sByte();

        public JSONSerializer<Short> sShort();

        public JSONSerializer<Integer> sInteger();

        public JSONSerializer<Long> sLong();

        public JSONSerializer<Float> sFloat();

        public JSONSerializer<Double> sDouble();

        public JSONSerializer<Boolean> sBoolean();

    }

    public static interface Serializers extends JSONSerializerFactory {

        public JSONSerializer<List<Integer>> listOfIntegers();

        public JSONSerializer<Integer[]> arrayOfIntegers();

        public JSONSerializer<RaynorTestClasses.Person> person();

        public JSONSerializer<RaynorTestClasses.MaybePerson> maybePerson();

        public JSONSerializer<RaynorTestClasses.Review<RaynorTestClasses.Person>> reviewOfPerson();

        public JSONSerializer<RaynorTestClasses.Option<Integer>> optionalInteger();

        public JSONSerializer<RaynorTestClasses.ClassWithNoArgConstructor> classWithNoArgConstructor();

    }

    public static interface SerializerForInvalidRawType extends JSONSerializer<RaynorTestClasses.Option> {
    }

    public static interface SerializerForForbiddenType extends JSONSerializer<Object> {
    }

    public static interface SimpleService extends JSONService {
        public void getSame(RaynorTestClasses.Person input, AsyncCallback<RaynorTestClasses.Person> callback);
    }
}
